package com.example.pt.controller;


import com.example.pt.entity.TorrentFile;
import com.example.pt.enums.Category;
import com.example.pt.service.TorrentFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
@CrossOrigin(origins = "*")
public class TestESController {

    @Autowired
    private TorrentFileService torrentFileService;

    /**
     * 测试上传的功能
     * @param title
     * @param str_category
     * @param format
     * @param language
     * @param description
     * @param file
     * @return
     */

    @PostMapping("/upload")
    public Map<String, Object> uploadTest(@RequestParam("title") String title,
                                          @RequestParam("category") String str_category,
                                          @RequestParam("format") String format,
                                          @RequestParam("language") String language,
                                          @RequestParam("description") String description,
                                          @RequestPart("file") MultipartFile file
    ){

        try {
            int uid = 123321;
            //torrentFileService.uploadTorrentFile("test", uid, title, category, format, language, description, 12313L);
            int category = Category.getValueByName(str_category);
            torrentFileService.uploadTorrentFileTest("test2", uid, title, category, format, language, description, 1231332L);
        }catch (Exception e){
            e.printStackTrace();
        }

        Map<String, Object> map = new HashMap<>();
        map.put("status", "success");
        map.put("message", "success");
        return  map;
    }
}
